/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.data.redis.factory;

import io.lettuce.core.resource.ClientResources;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.data.redis.connection.ReactiveRedisClusterConnection;
import org.springframework.data.redis.connection.ReactiveRedisConnection;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.tianyun.cloud.data.redis.configuration.RedisContainerProperties;

/**
 * 扩展SpringRedisConnectionFactory，实现ReactiveRedisConnectionFactory接口
 *
 * @auther ebert_chan
 */
public class SpringReactiveRedisConnectionFactory extends SpringRedisConnectionFactory implements ReactiveRedisConnectionFactory {

    public SpringReactiveRedisConnectionFactory(RedisContainerProperties properties, ObjectProvider<ClientResources> clientResourceProvider) {
        super(properties, clientResourceProvider);
    }

    /*
     * @see org.springframework.data.redis.connection.ReactiveRedisConnectionFactory#getReactiveConnection()
     */
    @Override
    public ReactiveRedisConnection getReactiveConnection() {
        ReactiveRedisConnectionFactory reactiveRedisConnectionFactory = this.getReactiveRedisConnectionFactory();
        // return null disable health check
        //Assert.notNull(reactiveRedisConnectionFactory, "This 'redisConnectionFactory' is not 'ReactiveRedisConnectionFactory' instance.");
        if (reactiveRedisConnectionFactory == null) {
            return null;
        }
        return reactiveRedisConnectionFactory.getReactiveConnection();
    }

    /*
     * @see org.springframework.data.redis.connection.ReactiveRedisConnectionFactory#getReactiveClusterConnection()
     */
    @Override
    public ReactiveRedisClusterConnection getReactiveClusterConnection() {
        ReactiveRedisConnectionFactory reactiveRedisConnectionFactory = this.getReactiveRedisConnectionFactory();
        // return null disable health check
        //Assert.notNull(reactiveRedisConnectionFactory, "This 'redisConnectionFactory' is not 'ReactiveRedisConnectionFactory' instance.");
        if (reactiveRedisConnectionFactory == null) {
            return null;
        }
        return reactiveRedisConnectionFactory.getReactiveClusterConnection();
    }

}
